﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Collections.Specialized;
using Story.Library;
using Nini.Config;

namespace Story.Framework
{
    /// <summary>
    /// 服务器端相关配置信息的处理器
    /// </summary>
    public class ServerConfiguration : IConfigurationSectionHandler
    {
        private static string m_ConnectionString;
        #region IConfigurationSectionHandler 成员
        /// <summary>
        /// 服务器端数据库连接字符串
        /// ConnectionString
        /// </summary>
        public static string ConnectionString
        {
            get
            {
                return m_ConnectionString;
            }
        }
        public object Create(object parent, object configContext, System.Xml.XmlNode section)
        {
            NameValueCollection settings;
            try
            {
                 NameValueSectionHandler baseHandler = new NameValueSectionHandler();
                settings = (NameValueCollection)baseHandler.Create(parent, configContext, section);
            }
            catch
            {
                
               settings = null;
            }
            if (settings == null)
            {
                m_ConnectionString = "";
            }
            else
            {
                m_ConnectionString = ConfigHelper.ReadSetting(settings, "ConnectionString", "");
            }
            return settings;
        }

        #endregion
        private static IConfigSource source;
        public static IConfigSource ConfigSource
        {
            get { return source; }
        }
        public static void ConfigXml(string xmlFileName)
        {
            source = new XmlConfigSource(xmlFileName);
            m_ConnectionString = source.Configs["Logging"].Get("ConnectionString");
        }
    }
}
